package simulator.engine;


import java.util.ArrayList;
import java.util.regex.Pattern;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author 500384
 */
public class Illumination 
{
    /*
     * hente data fra database/XML
     * velge hvilke lamper som skal bruke energi basert på sliderdata
     * regne ut hvor mye energi som blir brukt pr time og pr døgn
     * sende energi
    */
    private float[] input =  {0.2f, 0.3f, 0.4f, 0.5f, 
        0.6f, 0.7f, 0.8f, 0.9f, 0.1f, 0.2f, 0.3f, 0.4f, 0.6f, 0.7f, 0.8f, 0.9f, 
        1f, 0.4f, 0.5f, 0.6f, 0.7f, 0.6f, 0.7f, 0.9f};
    
    private  int numberOfLights;
    private  double kwPrHour; 
    
    //default constructor for this object
    public Illumination () { }
    
    //constructor which instantiates an object with the required fields number 
    //of lights and the electrical usage for an average light unit
    public Illumination(int numberOfLights, double kwPrHour) {
        this.numberOfLights = numberOfLights;
        this.kwPrHour = kwPrHour;
    }

    public int getNumberOfLights() {
        return numberOfLights;
    }

    public void setNumberOfLights(int numberOfLights) {
        this.numberOfLights = numberOfLights;
    }

    public double getKwPrHour() {
        return kwPrHour;
    }

    public void setKwPrHour(double kwPrHour) {
        kwPrHour = kwPrHour;
    }
    
    //calculates the total electrical consumption of a building when all lights are powered on
    public double MaximumUsage() {       
        double watt = kwPrHour / 1000D;
        double energyInKw = numberOfLights * watt;
        return energyInKw;
    }
    
    public void setUserPattern(String userPattern)
    {
        String pattern = userPattern;
        pattern = pattern.replaceAll("\\s", ""); 
        String[] arr = pattern.split(",");
        float[] array = new float[arr.length];
        
        for(int i = 0; i < array.length; i++)
        {
            array[i] = Float.parseFloat(arr[i]);
            //double out = Double.parseDouble(array[i]) * MaximumUsage();
            //System.out.println(out + "");
        }
        input = array;
    }
    
    public void setUserPattern(float[] ar)
    {
        this.input = ar;
    }
    
    
    //returns an array of numbers representing the hour-by-hour consumption of the building
    public float CalculateUsage(short hour) 
    {
        float timeOfDay = input[hour];
        return (float)MaximumUsage() * timeOfDay;
    }
    
    
    /**
     * KOMENTER!!!
     * @param args 
     */
    public static void main(String []args) {
        //System.out.println("Energiforbruk i kW-timer: " + CalculateEnergyUsage());
        /*int maxForbruk = 500000;
        String s = "12.5, 56.7, 89.3";
        s = s.replaceAll("\\s", "");
        String[] a = s.split(",");
        
        for(int i = 0; i < a.length; i++)
        {
            double out = Double.parseDouble(a[i]) * maxForbruk / 100;
            System.out.println(out + "");
        }
        * */
        Illumination i = new Illumination(12, 23);
        System.out.println(i.CalculateUsage((short)3));
    }
    
}
